package com.hahaliu.hahaliu.service.impl.search;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hahaliu.hahaliu.mapper.UserMapper;
import com.hahaliu.hahaliu.mapper.VideoMapper;
import com.hahaliu.hahaliu.pojo.entity.User;
import com.hahaliu.hahaliu.pojo.entity.Video;
import com.hahaliu.hahaliu.pojo.vo.SearchCountVO;
import com.hahaliu.hahaliu.service.search.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SearchServiceImpl implements SearchService {
	@Autowired
	private VideoMapper videoMapper;

	@Autowired
	private UserMapper userMapper;


	@Override
	public SearchCountVO getCount(String keyword) {
		// 创建查询条件对象
		QueryWrapper<Video> queryWrapper = new QueryWrapper<>();
		// 设置模糊查询条件，假设关键字为 keyword
		queryWrapper.like("title", keyword);

		// 执行查询操作并获取匹配的记录数量
		Long videoCount = videoMapper.selectCount(queryWrapper);

		// 创建查询条件对象
		QueryWrapper<User> queryWrapper2 = new QueryWrapper<>();
		// 设置模糊查询条件，假设关键字为 keyword
		queryWrapper2.like("nickname", keyword);

		// 执行查询操作并获取匹配的记录数量
		Long userCount = userMapper.selectCount(queryWrapper2);

		SearchCountVO searchCountVO = new SearchCountVO();
        searchCountVO.setVideoCount(Math.toIntExact(videoCount));
        searchCountVO.setUserCount(Math.toIntExact(userCount));

        return searchCountVO;
	}
}
